﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Common.Tools
{
    public static class UtilMethod
    {/// <summary>
        /// 产生一个5位数字的随机数
        /// </summary>
        /// <returns></returns>
        public static int GetRandomForFive()
        {
            Random ran = new Random();
            return ran.Next(99999);
        }
        /// <summary>
        /// 当前操作系统版本是否大于Vista
        /// </summary>
        /// <returns></returns>
        public static bool IsVistaUpOS()
        {
            OperatingSystem os = Environment.OSVersion;
            if (os.Version.Major >= 6)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //将image转化为二进制 
        public static byte[] GetByteImage(Image img)
        {

            byte[] bt = null;

            if (img!=null)
            {
                using (MemoryStream mostream = new MemoryStream())
                {
                    Bitmap bmp = new Bitmap(img);

                    bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Jpeg);//将图像以指定的格式存入缓存内存流

                    bt = new byte[mostream.Length];

                    mostream.Position = 0;//设置留的初始位置

                    mostream.Read(bt, 0, Convert.ToInt32(bt.Length));

                }

            }

            return bt;

        }
       
    }
}
